package com.yuanfengPlus.utils;

import java.lang.reflect.Field;
import java.util.Map;

public class ObjectValidator {
    public static boolean checkObject(Object obj, Map<String, String> fieldErrorMessages) {
        if (obj == null) {
            return false;
        }
        Class<?> clazz = obj.getClass();
        for (Map.Entry<String, String> entry : fieldErrorMessages.entrySet()) {
            try {
                Field field = clazz.getDeclaredField(entry.getKey());
                field.setAccessible(true);
                Object value = field.get(obj);
                if (value == null || (value instanceof String && ((String) value).isEmpty())) {
                    return false;
                }
            } catch (NoSuchFieldException | IllegalAccessException e) {
                // 可以根据需要进行更详细的异常处理，例如记录日志
                return false;
            }
        }
        return true;
    }
}